//
// GridWorksView.java
//
//	The view controls rendering and contains the game
//	thread.  The game thread is managed here.
//  
//	By: JCioffi
//  At: 5/7/2012
//
package com.BEASTMODE.games;

import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.graphics.Canvas;
import android.content.Context;

public class GridWorksView extends SurfaceView
{
	private SurfaceHolder sh;
	private GameThread gt;
	
	public GridWorksView(Context cntxt)
	{
		super(cntxt);
		gt = new GameThread(this);
		sh = getHolder();
		sh.addCallback(new SurfaceHolder.Callback()
		{
			public void surfaceDestroyed(SurfaceHolder holder)
			{
				// TODO Auto-generated method stub
				gt.Stop();
				while (true)
				{
					try
					{
						gt.join();
						break;
					}
					catch (InterruptedException e)
					{
						// log fail with exception message
					}
				}
			}
			
			public void surfaceCreated(SurfaceHolder holder)
			{
				// TODO Auto-generated method stub
				gt.Start();
			}
			
			public void surfaceChanged(SurfaceHolder holder, int format, int width,
					int height)
			{
				// TODO Auto-generated method stub
				
			}
		});
		//this.setOnTouchListener(l)
	}
	
	@Override
	protected void onDraw(Canvas canvas)
	{
		//gt.Draw(canvas);
	}
}
